package org.sgroup.imenu;

import org.sgroup.imenu.util.SyncIData;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class LoadingActivity extends Activity implements
		DialogInterface.OnDismissListener {
	SyncIData synsData;
	Context actvitiyContext;
	Activity _this;
	ProgressDialog progressDialog;
	Toast msg;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		if (android.os.Build.VERSION.SDK_INT > 9) {
			StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
					.permitAll().build();
			StrictMode.setThreadPolicy(policy);
		}
		super.onCreate(savedInstanceState);
		actvitiyContext = this.getApplicationContext();
		setContentView(R.layout.activity_loading);
		((RelativeLayout) findViewById(R.id.RelaLoading))
				.setBackgroundResource(R.drawable.i_bg);
		progressDialog = new ProgressDialog(this);
		_this = this;

		progressDialog.setTitle(" ");
		progressDialog.setMessage("Loading...");
		progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		progressDialog.setIndeterminate(false);
		progressDialog.setMax(100);
		progressDialog.setIcon(R.drawable.default_logo);
		progressDialog.setOnDismissListener(this);
		progressDialog.setCancelable(true);
		progressDialog.show();

		synsData = new SyncIData(actvitiyContext, progressDialog);
		final Boolean issyn = synsData.SynAllData();
		msg = Toast.makeText(actvitiyContext, R.string.err_connect,
				Toast.LENGTH_LONG);
		if (!issyn) {
			msg.show();
			_this.finish();
		} else {
			// progressDialog.dismiss();
			// Intent openActivity = new Intent(
			// "android.intent.action.IMENU");
			// System.gc();
			// startActivity(openActivity);
		}

	}

	@Override
	public void onDismiss(DialogInterface arg0) {
		Intent openActivity = new Intent("android.intent.action.IMENU");
		System.gc();
		startActivity(openActivity);

	}
}
